﻿using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Queer.Mqtt.Core.Model;
using System.Threading;

namespace Queer.Mqtt
{

    [AppStartup(1)]
    public class MqttAppStartup : AppStartup
    {

        public void ConfigureServices(IServiceCollection services)
        {
            // 读取配置
            services.AddConfigurableOptions<MqttConfig>();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            Thread thread = new Thread(async () =>
            {
                // 挂起60秒，减少启动时间
                Thread.Sleep(60 * 1000);

                // MQTT客户端服务
                await MqttClientCenter.OpenConnectAsync();
            });

            thread.Start();
        }
    }
}